//splice() 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组。

//start​：指定修改的开始位置（从0计数）。如果超出了数组的长度，则从数组末尾开始添加内容；如果是负值，则表示从数组末位开始的第几位（从-1计数，这意味着-n是倒数第n个元素并且等价于array.length-n）；如果负数的绝对值大于数组的长度，则表示开始位置为第0位。
const months = ['Jab', 'March', 'April', 'June']
months.splice(1, 0, 'Feb')
console.log(months)
months.splice(4, 1, 'May')
console.log(months)

//从第二位开始删除0个元素，插入'drum'
// var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
// var removed = myFish.splice(2, 0, 'drum')
// console.log(myFish)

//从第二位开始删除0个元素，插入drum和guitar
// var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
// var removed = myFish.splice(2, 0, 'drum', 'guitar')
// console.log(myFish)

//从第三位开始删除一个元素
// var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
// var removed = myFish.splice(3, 1)
// console.log(myFish)

//从第二位开始删除一个元素，插入trumpet
// var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
// var removed = myFish.splice(3, 1, 'trumpet')
// console.log(myFish)

//从第0位开始删除两个元素，插入parrot、anemone、blue
// var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
// var removed = myFish.splice(0, 2, 'parrot', 'anemone', 'blue')
// console.log(myFish)

//从第二位开始删除两个元素
// var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
// var removed = myFish.splice(2, 2)
// console.log(myFish)

//从倒数第二位开始删除一个元素
// var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
// var removed = myFish.splice(-2, 1)
// console.log(myFish)

//从第二位开始删除所有元素
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
var removed = myFish.splice(2)
console.log(myFish)
